<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>专家回复页面</title>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../res/layui/layui.js"></script>
    <script src="../../res/js/Tools.js"></script>

</head>
<body>
<div id="container">
<form class="layui-form" id="atsSchemeForm">
    <input type="hidden" name="schemeId" id="schemeId" lay-verify="schemeId" autocomplete="off" class="layui-input">
    <input type="hidden" name="seId" id="seId" lay-verify="seId" autocomplete="off" class="layui-input">
    <input type="hidden" name="remark" id="remark" lay-verify="remark" autocomplete="off" class="layui-input">
    <div class="layui-form-item"></div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">方案名称</label>
        <div class="layui-input-block">
            <input class="layui-input" type="text" readonly unselectable="on" name="schemeName"  id="schemeName" required
                   lay-verify="required" placeholder="方案名称" autocomplete="off"/>
        </div>
    </div>
    <label class="layui-form-label"></label>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">申请理由</label>
        <div class="layui-input-block">
            <input class="layui-input" type="text" readonly unselectable="on" name="applyForExp"  id="applyForExp" required
                   lay-verify="required" placeholder="申请理由" autocomplete="off"/>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">申请人</label>
        <div class="layui-input-block">
            <input class="layui-input" type="text" readonly unselectable="on" name="creater"  id="creater" required
                   lay-verify="required" placeholder="申请人" autocomplete="off"/>
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">专家意见</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入专家意见" class="layui-textarea" name="results" id="results"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="button" class="layui-btn site-demo-active" lay-submit="" lay-filter="demo1" value="立即提交"/>
        </div>
    </div>
</form>
</div>
<style>
    body { font-family:Verdana; margin:0 auto;}
    #container {margin: 0 auto; width:600px;}
</style>
<script>

    //取到上一个页面传过来的id
    var schemeId = getQueryString("id");
    $("#schemeId").val(schemeId);
    $.ajax({
        url: "../../AtsSchemeFsController/selectExpertBySaId",
        type: "post",
        data:{saId:schemeId},
        dataType:"json",
        success:function(obj){
            $("#schemeName").val(obj.saName);
            $("#applyForExp").val(obj.applyForExp);
            $("#creater").val(obj.creater);
            $("#seId").val(obj.seId);
        }, error: function (e) {
            alert('失败了');
        }
    });


    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layedit=layui.layedit
            , laydate=layui.laydate
            , layer = layui.layer;

        var url1="../../AtsSchemeFsController/selectExpertBySaId";
        var data1={schemeId:schemeId};
        $.post(url1,data1,function (obj) {
            $("#schemeName").val(obj.saName);
            $("#schemeName").prop("disabled","disabled");
            $("#applyForExp").val(obj.applyForExp);
            $("#applyForExp").prop("disabled","disabled");
            $("#creater").val(obj.creater);
            $("#creater").prop("disabled","disabled");
        },"json");

        //自定义验证规则
        form.verify({
            results: function(value){
                if(!value.length){
                    return '专家意见不能包含空格';
                }
            }
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            // 单击之后提交按钮不可选,防止重复提交
            var DISABLED = 'layui-btn-disabled';
            // 增加样式
            $('.site-demo-active').addClass(DISABLED);
            // 增加属性
            $('.site-demo-active').attr('disabled', 'disabled');
            var url = "../../AtsSchemeFsController/UpdateReply";
            data.field.auditState="40";
            $.ajax({
                url: url, 
                type: "post",
                data:data.field,
                dataType: "json",
                success: function (obj) {
                    if(obj.num===1){
                        layer.msg(obj.msg, {
                            icon: 1,
                            time: 1000,
                        }, function () {
                            window.parent.location.reload();//刷新父页面
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }else{
                        layer.msg(obj.msg, {
                            icon: 2,
                            time: 1000,
                        }, function () {
                            window.parent.location.reload();//刷新父页面
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                    }
                }, error: function (e) {
                    alert('失败了');
                }

            });
        });


    });

</script>

</body>
</html>